package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsActionNotTimeout;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.car.controller.FindCarController;
import com.tianqu.tms.www.car.viewhelper.FindCarPriceListViewHelper;

public class FindCarPriceListAction extends TmsActionNotTimeout {
	private final int pageSize = 5;
	private Logger logger = Logger.getLogger(FindCarPriceListAction.class);
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response, UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		String p1 = request.getParameter("pageNumber");
		int pageNumber = StringUtils.isNumeric(p1)?Integer.parseInt(p1):1;
		//
		String type = !StringUtil.isNotBlank(request.getParameter("type"))?"1":request.getParameter("type");
		double minPrice = 0,maxPrice = 0;
		if("1".equals(type)){
			minPrice = 0;maxPrice=50000;
		}else if("2".equals(type)){
			minPrice = 50000;maxPrice=80000;
		}else if("3".equals(type)){
			minPrice = 80000;maxPrice=100000;
		}else if("4".equals(type)){
			minPrice = 100000;maxPrice=150000;
		}else if("5".equals(type)){
			minPrice = 150000;maxPrice=200000;
		}else if("6".equals(type)){
			minPrice = 200000;maxPrice=250000;
		}else if("7".equals(type)){
			minPrice = 250000;maxPrice=400000;
		}else if("8".equals(type)){
			minPrice = 400000;maxPrice=99999999;
		}
		//
		FindCarController controller = new FindCarController();
		FindCarPriceListViewHelper view = controller.FindCarPriceListController(minPrice,maxPrice, pageNumber, pageSize);
		view.setType(type);
		String title = request.getParameter("title");
		if(StringUtil.isNotBlank(title)) title  = new String(title.getBytes("ISO-8859-1"),"UTF-8");  
		view.setTitle(title);
		request.setAttribute(TmsConstants.VIEWHELP,view);
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
